package com.leonardo.persistenceme.model.persistancehandlers;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class BooleanPersistenceHandler extends PersistenceHandler {

	/**
	 * Persist a boolean field. By default is false
	 */
	public void persist(Object obj, DataOutputStream stream) throws IOException {
		if(obj == null) {
			stream.writeBoolean(false);
			return;
		}
		Boolean bool = (Boolean) obj;
		stream.writeBoolean(bool.booleanValue());
	}

	public Object recover(DataInputStream stream) throws IOException {
		return new Boolean(stream.readBoolean());
	}

}
